<?php

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class Cate extends Model
{
    //软删除
    use SoftDelete;

    //栏目添加
    public function cateadd($data)
    {
        $validate = new \app\common\validate\Cate();
        if (!$validate->scene('cateadd')->check($data)){
            return $validate->getError();
        }
        $result = $this -> allowField(true) -> save($data);
        if ($result){
            return 1;
        } else {
            return '栏目添加失败！';
        }

    }

    //栏目排序
    public function catesort($data)
    {
        $validate = new \app\common\validate\Cate();
        if (!$validate->scene('catesort')->check($data)){
            return $validate->getError();
        }
        $cateInfo = $this -> find($data['id']);
        $cateInfo -> sort = $data['sort'];
        $result = $cateInfo -> save();
        if ($result){
            return 1;
        } else {
            return '排序失败！';
        }

    }

    //栏目编辑
    public function cateedit($data)
    {
        $validate = new \app\common\validate\Cate();
        if (!$validate->scene('cateedit')->check($data)){
            return $validate->getError();
        }
        $cateInfo = $this -> find($data['id']);
        $cateInfo -> catename = $data['catename'];
        $result = $cateInfo -> save();
        if ($result){
            return 1;
        } else {
            return '栏目编辑失败！';
        }
    }

}
